package com.delong.lease.web.app.custom.config;

import com.delong.lease.web.app.custom.converter.StringToBaseEnumConverterFactory;
import com.delong.lease.web.app.custom.interceptor.LoginProtectHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author shangshang
 * @date 2024/9/29 13:13
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;

    @Autowired
    private LoginProtectHandlerInterceptor loginProtectHandlerInterceptor;

    @Value("${app.auth.path-patterns.include}")
    private String [] include;

    @Value("${app.auth.path-patterns.exclude}")
    private String [] exclude;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(this.stringToBaseEnumConverterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginProtectHandlerInterceptor).addPathPatterns(include).excludePathPatterns(exclude);
    }
}